/**
 * Created by Fly on 2016/9/18.
 */
var express = require('express');
var router = express.Router();
// var app_petDAO=require('../dao/app_petDao');
var petDAO=require('../dao/petDao');
var filter=require('../util/filter');
router.get('/', function(req, res) {
    if(req.session.userID==undefined){
        res.redirect('/login');
    }else {
        petDAO.getinfo(req,res,function(data){
            console.log(data);
            res.render('pet',{pet:data,username:req.session.userID});
        })
    }
});
router.post('/del', function(req,res) {
        petDAO.del(req.body.petno,function(result){
            if(result.affectedRows==1){
                res.json({res:"1"});
            }else{
                res.json({res:"0"});
            }
        });
});
router.get('/addpet', function(req, res) {
    if(req.session.userID==undefined){
        req.session.urldate='/pet/addpet';
        res.redirect('/login');
    }else {
        res.render('addpet',{username:req.session.userID});
    }
});
/******************************/
// router.get('/app_addpet', function(req, res) {
//     app_petDAO.add_pet(req,res,function(result){
//         res.jsonp({res:1})
//     });
//
// });
/*******************************/
router.post('/addpet',function(req,res){
    petDAO.add(req,res,function(result){
        if(result.affectedRows==1){
            res.json({res:"1"});
        }else{
            res.json({res:"0"});
        }
    });
});
module.exports = router;
